package com.terrier.ui.effects
{
    import com.greensock.TweenLite;
    
    import flash.display.DisplayObject;

    /**
     * 透明度动画特效
     *
     * @author Jarvis.weng
     */
    public class WxAlphaEffect extends WxAbstractEffect
    {
        private var _alphaOld:Number = 0;
        private var _alphaFrom:Number = 0;
        private var _alphaTo:Number = 1;

        /**
         * 构造函数
         * @param alphaFrom 初始的透明度
         * @param alphaTo 最终的透明度
         * @param target 特效作用对象
         */
        public function WxAlphaEffect(alphaFrom:Number, alphaTo:Number, runTime:Number = 0.5, 
									  target:DisplayObject = null,
									  startEventParams:Object = null,
									  updateEventParams:Object = null,
									  stopEventParams:Object = null)
        {
            super(target, runTime, startEventParams, updateEventParams, stopEventParams);

            _alphaFrom = alphaFrom;
            _alphaTo = alphaTo;
        }
		
		//--------------------------------------------------------
		//
		// Methods
		//
		//--------------------------------------------------------

        /**
         * @private
         */
        override protected function initialize():void
        {
			if(target != null)
			{
            	_alphaOld = target.alpha;
            	target.alpha = alphaFrom;
			}
        }
		
		override public function start():void
		{
			super.start();
			if(target != null)
			{
				TweenLite.to(target, runTime, {alpha:alphaTo, onComplete:stop});
			}
		}
		
        /**
         * @private
         */
        override public function restore():void
        {
			if(target != null)
			{
            	target.alpha = _alphaOld;
			}
        }
		
		override public function clone():IWxAbstractEffect
		{
			var newEffect:WxAlphaEffect = new WxAlphaEffect(this._alphaFrom,
				this._alphaTo, this.runTime, this.target, 
				this.startEventParams, this.updateEventParams, this.stopEventParams);
			return newEffect;
		}

		//--------------------------------------------------------
		//
		// Properties
		//
		//--------------------------------------------------------
		
        /**
         * 初始的透明度
         */
        public function get alphaFrom():Number
        {
            return _alphaFrom;
        }

        /**
         * 最终的透明度
         */
        public function get alphaTo():Number
        {
            return _alphaTo;
        }
    }
}